<?php
/**
 * @fileoverview
 * 负责解析用户信息的csv文件
 */

require_once("csv.php");

class User extends CSV {

	/**
	 * 映射关系
	 */
	var $map = array(
		'id',
		'username',
		'password',
		'email',
		'blog_name',
		'blog_url',
		'logo_url',
		'description',
		'validuser',
		'admin',
		'reserve_3',
		'reserve_4',
		'reserve_5',
		'reserve_6',
		'reserve_7',
		'reserve_8',
		'reserve_9',
	);

	function User($root=".") {
		$this->__constructor($root);
	}

	function __constructor($root=".") {
		parent::__constructor("$root/data/user.csv");
	}

	function read($id) {
		return parent::csv2obj(parent::read($id));
	}

	function read_all() {
		$users = parent::read_all();
		$result = array();
		for ($i = 0; $i < count($users); $i++) {
			array_push($result, parent::csv2obj($users[$i]));
		}
		return $result;
	}

	function write($id, $data) {
		if (empty($data["id"])) {
			$data["id"] = $id;
		}
		parent::write($id, parent::obj2csv($data));
	}

	function write_all($data) {
		$ar = array();
		while ($user = array_shift($data)) {
			array_push($ar, parent::obj2csv($user));
		}
		parent::write_all($ar);
	}
}

?>
